package com.example.homework_4_permission.pojo;

import lombok.Data;

@Data
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public static Result ok() {
        return new Result(200, "SUCCESS");
    }

    public static Result ok(String message) {
        return new Result(200, message);
    }

    public static Result ok(Object data) {
        return new Result(200, data);
    }

    public static Result ok(String message, Object data) {
        return new Result(200, message, data);
    }

    public static Result error() {
        return new Result(200, "ERROR");
    }

    public static Result error(String message) {
        return new Result(400, message);
    }

    public static Result error(String message, Object data) {
        return new Result(400, message, data);
    }

    public static Result insert(int count, String message) {
        if (count > 0) {
            return Result.ok(message);
        }
        return Result.error(message);
    }

    public static Result update(int count, String message) {
        if (count > 0) {
            return Result.ok(message);
        }
        return Result.error(message);
    }
}
